<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <div id="app">
        <div class="myson">
            <h1>父组件</h1>
            <div>
                <div>项目已运行{{num}}天</div>
            </div>
            <button @click="num++">增加</button>
        </div>


        <myson :a="num" title="子组件"></myson>
    </div>
    <script src="vue.js"></script>
    <script>
        const { ref, createApp, computed } = Vue;
        const app = createApp({
            setup(){
                let num =ref(100)
                return{
                    num
                }
            }
        })

        app.component('myson',{
            props:['a','title'],
            setup(props){
                let title=props.title
                let a =computed(function(){
                    return props.a
                })
                return{
                    a,
                    title
                }
            },
            template:`
            <div class="myson">
            <h2>{{title}}</h2>    
            {{a}}
            </div>
            `
        })

        app.mount("#app");

    </script>
</body>
</html>
<style>
   .myson {
    background-color: #f5f5f5;
    width: 300px;
    height: 200px;
    border: 2px solid #E84E40;
    text-align: center;
    margin: 50px auto;
   }
</style>